package org.msb.code.thread;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zhuchenglin
 * @since 2022/8/31 14:31
 */
public class SimpleDateFormatTest {

    ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(10, 100, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<>(1000));
    private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public void test() {
        while (true) {
            Lock lock = new ReentrantLock();
            poolExecutor.execute(() -> {
                lock.lock();
                String dateString = format.format(new Date());
                try {
                    Date parseDate = format.parse(dateString);
                    String dateString2 = format.format(parseDate);
                    System.out.println(dateString.equals(dateString2));
                } catch (ParseException e) {
                    e.printStackTrace();
                } finally {
                    lock.unlock();
                }
            });
        }
    }

    public static void main(String[] args) {
        SimpleDateFormatTest simpleDateFormatTest = new SimpleDateFormatTest();
        simpleDateFormatTest.test();
    }
}
